import request from '../utils/request.js'

// 获取文章详情的 API（形参中的 id 是文章的 id）
export const getArticleDetailAPI = id => {
  return request.get(`/v1_0/articles/${id}`)
}
export const followUserAPI = userId => {
  return request.post('/v1_0/user/followings', {
    target: userId
  })
}
export const unfollowUserAPI = function (id) {
  return request.delete('/v1_0/user/followings/' + id)
}

export const likeArticleAPI = artId => {
  return request.post('/v1_0/article/likings', {
    target: artId
  })
}
export const deslikeArticleAPI = id => {
  return request.delete('/v1_0/article/likings/' + id)
}
export const getCmtListAPI = (id, offset) => {
  return request.get('/v1_0/comments', {
    params: {
      // a 表示获取文章下的评论
      type: 'a',
      // 文章的 Id
      source: id,
      // 获取评论数据的偏移量，值为评论的 id。表示从此 id 的数据向后取，不传表示从第一页开始读取数据
      offset
    }
  })
}

export const pubCommentAPI = (artId, content) => {
  return request.post('/v1_0/comments', {
    target: artId,
    content
  })
}
